/*
 * buf_stream.hpp
 *
 *  Created on: 2021年2月7日
 *      Author: kimfeng
 */

#ifndef BUF_STREAM_HPP_
#define BUF_STREAM_HPP_

#include <cstring>
#include <inttypes.h>

static inline void buf_writebytes(uint8_t **pBuf, uint8_t *pSrc, uint32_t wlen)
{
	std::memcpy(*pBuf, pSrc, wlen);
	*pBuf += wlen;
}
static inline void buf_readbytes(uint8_t **pBuf, uint8_t *pDst, uint32_t wlen)
{
	std::memcpy(pDst, *pBuf, wlen);
	*pBuf += wlen;
}


template <typename valType>
static inline void buf_read(uint8_t** pBuf, valType *pValue)
{
	*pValue = *(valType *)(void *)(*pBuf);
	*pBuf += sizeof(valType);
}

template <typename valType>
static inline void buf_write(uint8_t** pBuf, valType value)
{
	*(valType*)(void*)(*pBuf) = value;
	*pBuf += sizeof(valType);
}

#endif /* BUF_STREAM_HPP_ */
